package com.xiaoyung.easyisapisdk.common.util.bean;
import org.apache.commons.beanutils.Converter;

import com.alibaba.fastjson2.JSON;
public class JSONConvert implements Converter{

	@SuppressWarnings("unchecked")
	@Override
	public <T> T convert(Class<T> type, Object value) {
		if(value==null) {
			return null;
		}
		if(value instanceof String) {
			T json = (T) JSON.parse((String)value);
			return json;
		}else if(JSON.class.isAssignableFrom(type)){//jsonObject jsonArray
			return (T) value;
		}else {
			//javabean
			return (T)JSON.toJSON(value);
		}
	}

}
